package com.fm.app03;

import static android.app.ProgressDialog.show;
import static com.fm.app03.Service.float_service.FloatingWidgetService.float_window;
import static com.fm.app03.Service.float_service.FloatingWidgetService.openAccessibilitySettingsIfNecessary;
import static com.fm.app03.os.MyApplication.instance;
import static com.fm.app03.os.utils.showShortToast;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.Settings;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import com.fm.app03.Activity.DaDiShuActivity;
import com.fm.app03.Activity.JiSuanQiActivity;
import com.fm.app03.Activity.Price_QueryActivity;
//import com.fm.app03.Activity.lianxirenActivity;
import com.fm.app03.Activity.projectActivity;
import com.fm.app03.Activity.starActivity;
import com.fm.app03.Activity.registerActivity;
import com.fm.app03.Activity.webActivity;
import com.fm.app03.Service.float_service.MyAccessibilityService;
import com.fm.app03.os.MyApplication;
import com.yhao.floatwindow.FloatWindow;

import java.util.List;


public class MainActivity extends AppCompatActivity {

    private static final String TAG = "MainActivity";
    private boolean IsSuspension = true;

    private Context context;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        //调用父类的onCreate方法来执行基本的Activity创建操作。
        super.onCreate(savedInstanceState);
        context = this.getApplicationContext();
        //设置当前Activity的布局文件为activity_main。
        setContentView(R.layout.activity_main);
        showShortToast(context,"开始喽~");
        linkTo(R.id.jiSuanQi, JiSuanQiActivity.class, "计算器界面");
        linkTo(R.id.mySite, webActivity.class, "我的网站");
        linkTo(R.id.click, registerActivity.class, "注册界面");
        linkTo(R.id.star, starActivity.class, "星座界面");
        linkTo(R.id.price, Price_QueryActivity.class, "酒店价格查询界面");
        linkTo(R.id.daDiShu, DaDiShuActivity.class, "打地鼠");
//        linkTo(R.id.lianxiren, lianxirenActivity.class, "通讯录");
        linkTo(R.id.project, projectActivity.class, "期末作业连连看");
    }


    /*点击悬浮框*/
    public void onShowBubbleButtonClick(View view) {
        Intent intent = new Intent(android.provider.Settings.ACTION_ACCESSIBILITY_SETTINGS);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);
    }



    /**
     * 跳转
     *
     * @param ID
     * @param tOActivityClass
     * @param description
     */
    /*界面跳转到*/
    private void linkTo(int ID, Class<?> tOActivityClass, String description) {
        /************************监听按钮***************************************/
        Button myButton2 = (Button) findViewById(ID);
        myButton2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 跳转界面
                startActivity(new Intent(MainActivity.this, tOActivityClass));
                /*所有界面可见*/
                showShortToast(context,"跳转到" + description);
            }
        });
    }



    /*服务跳转*/
    private void linkToService(int ID, Class<?> tOActivityClass, String description) {
        /************************监听按钮***************************************/
        Button myButton2 = (Button) findViewById(ID);
        myButton2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 跳转界面
                startService(new Intent(MainActivity.this, tOActivityClass));
                /*所有界面可见*/
                showShortToast(context,"跳转到" + description);
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                    if (!Settings.canDrawOverlays(MainActivity.this)) {
                        Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
                                Uri.parse("package:" + getPackageName()));
                        startActivityForResult(intent, 1000);
                    }
                }
            }
        });
    }


}
 
